﻿using System.Text;
using System.Collections.Specialized;
using Newtonsoft.Json;

namespace CometDocs
{
    internal partial class Client
    {
        private static readonly JsonConverter ConversionTypeJsonConverter = new ConversionTypeJsonConverter();

        /// <summary>
        /// Get the list of all the available conversion types: https://www.cometdocs.com/developer/apiDocumentation#method-getConversionTypes
        /// </summary>
        /// <returns>An array of conversion types.</returns>
        public ConversionType[] GetConversionTypes()
        {
            byte[] result = webClient.UploadValues(APIRoot + "getConversionTypes", new NameValueCollection());

            string json = Encoding.ASCII.GetString(result);

            GetConversionTypesResponse response = JsonConvert.DeserializeObject<GetConversionTypesResponse>(json, ConversionTypeJsonConverter);

            CheckAndThrow(response);

            return response.ConversionTypes;
        }
    }
}
